package com.ruantu.clothing.controller;

import com.ruantu.clothing.entity.JsonResponseMessage;
import com.ruantu.clothing.entity.PageBean;
import com.ruantu.clothing.entity.Store;
import com.ruantu.clothing.entity.User;
import com.ruantu.clothing.service.StoreService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

/**
 * Created by Administrator on 2018/7/25 0025.
 */
@Controller
@RequestMapping("/store")
public class StoreController {
    @Autowired
    private StoreService storeService;

    /**
     * 查询所有库存
     *
     * @return
     */
    @RequestMapping("/list")
    @ResponseBody
    public JsonResponseMessage findStoreList(Store store, PageBean pageBean, HttpSession session) {
        if (!StringUtils.isNotBlank(store.getJgId())) {
            User user = (User) session.getAttribute("info");
            store.setJgId(user.getJgid());
        }
        JsonResponseMessage jsonResponseMessage = new JsonResponseMessage();
        jsonResponseMessage.setRows(storeService.findStores(store, pageBean));
        jsonResponseMessage.setTotal(pageBean.getTotal());
        return jsonResponseMessage;
    }

    /**
     * 查询-库存
     *
     * @param selectText
     * @param leiXing
     * @param shuLiang
     * @param ordTJ
     * @param pageBean
     * @param //session
     * @return
     */
    @RequestMapping("/selectStoreByTJ")
    @ResponseBody
    public JsonResponseMessage selectStoreByTJ(String jgid, String selectText, Integer leiXing, Integer shuLiang,String cpYear,String season, String pinpai,Integer ordTJ, PageBean pageBean) {
        // System.out.println(cpYear+"--"+season+"--"+pinpai);
        JsonResponseMessage jsonResponseMessage = new JsonResponseMessage();
        jsonResponseMessage.setRows(storeService.selectStoreByTJ(jgid, selectText, leiXing, shuLiang,cpYear,season,pinpai, ordTJ, pageBean));
        jsonResponseMessage.setTotal(pageBean.getTotal());

        return jsonResponseMessage;
    }

}
